package com.ecloud.support.generator.custom;

import com.baomidou.mybatisplus.annotation.DbType;

/**
 * DatabaseEnum
 *
 * @author LiuGangQiang Create in 2021/04/24
 */
public enum DatabaseEnum {

    /**
     * MYSQL5X
     *
     * @author LiuGangQiang Create in 2021/04/25
     */
    MYSQL5X("MySQL 5.X", "com.mysql.cj.jdbc.Driver", DbType.MYSQL),
    /**
     * MYSQL8X
     *
     * @author LiuGangQiang Create in 2021/04/25
     */
    MYSQL8X("MySQL 8.X", "com.mysql.cj.jdbc.Driver", DbType.MYSQL),
    /**
     * Oracle数据库
     *
     * @author LiuGangQiang Create in 2021/04/24
     */
    ORACLE11G("Oracle 11G", "oracle.jdbc.driver.OracleDriver", DbType.ORACLE),
    /**
     * 未定义
     *
     * @author LiuGangQiang Create in 2021/04/24
     */
    UNDEFINED("undefined", "undefined", DbType.OTHER);

    private String type;
    private String driver;
    private DbType dbType;

    /**
     * 构造器
     *
     * @author LiuGangQiang Create in 2021/04/24
     * @param type   类型名
     * @param driver 驱动路径
     * @param dbType 对应Mybatis的数据库类型
     */
    private DatabaseEnum(String type, String driver, DbType dbType) {
        this.type = type;
        this.driver = driver;
        this.dbType = dbType;
    }

    /**
     * @return the type
     */
    public String getType() {
        return type;
    }

    /**
     * @return the driver
     */
    public String getDriver() {
        return driver;
    }

    /**
     * @return the dbType
     */
    public DbType getDbType() {
        return dbType;
    }

    /**
     * 字符串转枚举 不匹配默认为未定义
     *
     * @author LiuGangQiang Create in 2020/12/27
     * @param text 字符串
     * @return {@link DatabaseEnum}
     */
    public static DatabaseEnum fromType(String text) {
        for (DatabaseEnum type : DatabaseEnum.values()) {
            if (type.type.equalsIgnoreCase(text)) {
                return type;
            }
        }
        return UNDEFINED;
    }
}
